/*                                                     
 * $Id: hello.c,v 1.5 2004/10/26 03:32:21 corbet Exp $ 
 */                                                    
#include <linux/init.h>
#include <linux/module.h>
#include <linux/string.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
	char *line;
	char *ptr = NULL;
        char *ptr_end = NULL;
        char ethaddr[18];
	unsigned char	dev_addr[6];
	int i;
	
	line = "eth0addr=00:09:95:56:d2:43 eth1addr=00:09:95:56:d2:44 console=ttyBF0,115200 root=/dev/mtdblock0 rw";
	ptr = strstr(line, "eth0addr=");
	if(ptr) {
        	memcpy(ethaddr, ptr + 9, 17 * sizeof(char));
		ethaddr[17] = '\0';
                printk(KERN_INFO "ethaddr parsed from commandline: %s\n", ethaddr);

/*		printk(KERN_INFO "ethaddr=0x%p\n", ethaddr);

		for (i = 0; i < 17; i++) {
			printk(KERN_INFO "eth0addr[%d]=%x\n", i, ethaddr[i]);
		}
*/
                ptr_end = ethaddr;
//		printk(KERN_INFO "ptr_end=0x%p\n", ptr_end);
		
		for (i = 0; i < 6; i++) {
//			printk(KERN_INFO "ptr_end=0x%p\n", ptr_end);
			dev_addr[i] = simple_strtol(ptr_end, &ptr_end, 16) | simple_strtol(ptr_end, &ptr_end, 16) <<4;
			printk(KERN_INFO "dev_addr[%d]=%x ptr_end=0x%p\n", i, dev_addr[i], ptr_end);
                     	ptr_end++; /* skip ":" in  ethaddr */
			printk(KERN_INFO "ptr_end=0x%p\n", ptr_end);
                }
	}

	return 0;
}

static void hello_exit(void)
{
	printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);
